package com.yl.chainStore.entity.warehouse

import com.baomidou.mybatisplus.annotation.IdType
import com.baomidou.mybatisplus.annotation.TableField
import com.baomidou.mybatisplus.annotation.TableId
import com.baomidou.mybatisplus.annotation.TableName
import com.yl.chainStore.common.Constants
import com.yl.users.common.NeedGerId
import com.yl.chainStore.common.enums.Status
import com.yl.common.annotation.NoArg
import java.math.BigDecimal
import java.math.RoundingMode

/**
 * <p>
 * 调度明细
 * </p>
 *
 * @author cxw
 * @since 2021-06-10
 */
@NoArg
@TableName("warehouse_dispatch_order_detail")
class WarehouseDispatchOrderDetail  (

    /**
     * id
     */
    @TableId(value = "id", type = IdType.AUTO)
    var id: Long,

    /**
     * 调度订单id
     */
    @TableField("dispatch_order_id")
    var dispatchOrderId: Long? = null,

    /**
     * 物品id
     */
    @TableField("item_id")
    var itemId: Long,

    @TableField(exist = false)
    var itemName:String?=null,

    @TableField(exist = false)
    var unit: String? = null,

    @TableField(exist = false)
    var specification: String? = null,


    /**
     * 单价
     */
    @TableField("good_price")
    var goodPrice: Long=0,

    /**
     * 物品数量
     */
    @TableField("good_count")
    var goodCount: Int = 0,

    /**
     * 备注
     */
    @TableField("remark")
    var remark: String? = null,

    /**
     * 数据有效性
     */
    @TableField("enabled")
    var enabled: Int = 1,

    /**
     * 状态
     */
    @TableField("in_status")
    var inStatus: Status = Status.UNKNOWN,

    /**
     * 状态
     */
    @TableField("out_status")
    var outStatus: Status = Status.UNKNOWN,


    /**
     * 出库关联仓库内批次物品id
     */
    @TableField("out_warehouse_good_batch_id")
    var outWarehouseGoodBatchId: Long? = null
){

    /**
     * 实际要显示的实际总金额
     */
    @TableField(exist = false)
    var sumMoneyShow: BigDecimal?= null
        get() {
            if(field == null ){
                val sumMoney = goodPrice * goodCount
                return BigDecimal(sumMoney.div(Constants.OtherConfig.MONEY_TO_DB_DOUBLE)).setScale(2, RoundingMode.HALF_UP)
            }
            return field
        }
        set(value) {
            if(value != null){
                val sumMoney = (value.multiply(BigDecimal(Constants.OtherConfig.MONEY_TO_DB_DOUBLE))).toLong()
                goodPrice = sumMoney/goodCount
                field = value
            }
        }

    /**
     * 实际要显示的单价
     */
    @TableField(exist = false)
    var realGoodPrice: BigDecimal?= null
        get() {
            if(field == null){
                return BigDecimal(goodPrice.div(Constants.OtherConfig.MONEY_TO_DB_DOUBLE)).setScale(2, RoundingMode.HALF_UP)
            }
            return field
        }
        set(value) {
            if(value != null){
                goodPrice = (value.multiply(BigDecimal(Constants.OtherConfig.MONEY_TO_DB_DOUBLE))).toLong()
                field = value
            }
        }
}
